let now_pic = 0
let num_pic = $('.ul_lunbo')[0].children.length - 1
let timer = null
$('.lunbo_left').click(() => {
    clearInterval(timer)
    if (now_pic == 0) {
        now_pic = num_pic
        $('.ul_lunbo').css({
            left: -1920 * num_pic
        })
    }
    now_pic--
    btn_color()
    $('.ul_lunbo').animate({
        left: -1920 * now_pic
    }, auto)
})
$('.lunbo_right').click(() => {
    clearInterval(timer)
    if (now_pic == num_pic) {
        now_pic = 0
        $('.ul_lunbo').css({
            left: 0
        })
    }
    now_pic++
    btn_color()
    $('.ul_lunbo').animate({
        left: -1920 * now_pic
    }, auto)
})
// 自动播放的方法
function auto() {
    timer = setInterval(() => {
        $('.lunbo_right')[0].click()
    }, 2000)
}
auto()
// 根据图片数生成轮播图导航
for (let i = 0; i < num_pic; i++) {
    let text = '<li><a href="javascript:;"></a></li>'
    $('.lunbo_nav').append(text)
}
$('.lunbo_nav > li:nth-child(1) > a').css({
    backgroundColor: 'red'
})
let a_arr = $('.lunbo_nav>li>a')
for (let i = 0; i < a_arr.length; i++) {
    $(`.lunbo_nav>li:nth-child(${i + 1})`).click(() => {
        clearInterval(timer)
        now_pic = i
        btn_color()
        $(".ul_lunbo").animate({
            left: now_pic * -1920
        }, auto)

    })
}
function btn_color() {
    let i = now_pic
    i %= a_arr.length
    for (let i = 0; i < a_arr.length; i++) {
        a_arr[i].style.backgroundColor = ""
    }
    a_arr[i].style.backgroundColor = "red"
}
$('.button_search').click(() => {
    $('.form_search').submit()
})